﻿using Microsoft.AspNetCore.Mvc;
using System;
using ZhongKeSite.Common;
using ZhongKeSite.Common.Helper;
using ZhongKeSite.Entity;
using ZhongKeSite.Service;
using ZhongKeSite.Web.Models;

namespace ZhongKeSite.Web.Controllers
{
    [Auth]
    public class HomeController : Controller
    {
        IPortalService portalService;
        public HomeController(IPortalService _portalService)
        {
            portalService = _portalService;
        }

        #region 首页
        /// <summary>
        /// 首页
        /// </summary>
        /// <returns></returns>
        [Route("~/")]
        [Route("~/index")]
        [Route("~/index.html")]
        public IActionResult Index()
        {
            return View();
        }
        #endregion

        #region 智能硬件
        /// <summary>
        /// 智能硬件
        /// </summary>
        /// <returns></returns>
        [Route("~/hardware")]
        [Route("~/hardware.html")]
        public IActionResult Hardware()
        {
            return View();
        }
        /// <summary>
        /// 智能硬件
        /// </summary>
        /// <returns></returns>
        [Route("~/product")]
        [Route("~/product.html")]
        public IActionResult Product()
        {
            return View();
        }
        #endregion

        #region 解决方案
        /// <summary>
        /// 解决方案
        /// </summary>
        /// <returns></returns>
        [Route("~/solution")]
        [Route("~/solution.html")]
        public IActionResult Solution()
        {
            return View();
        }
        #endregion

        #region 故事
        /// <summary>
        /// 故事
        /// </summary>
        /// <returns></returns>
        [Route("~/story")]
        [Route("~/story.html")]
        public IActionResult Story()
        {
            try
            {
                return View(portalService.GetStoryInfo());
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return Content(CommonConst.SystemErrorMessage);
            }
        }
        #endregion

        #region 创新
        /// <summary>
        /// 创新
        /// </summary>
        /// <returns></returns>
        [Route("~/innovate")]
        [Route("~/innovate.html")]
        public IActionResult Innovate()
        {
            try
            {
                return View(portalService.GetInnovateInfo());
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return Content(CommonConst.SystemErrorMessage);
            }
        }
        /// <summary>
        /// 创新
        /// </summary>
        /// <returns></returns>
        [Route("~/innlist")]
        [Route("~/innlist.html")]
        public IActionResult InnList(int pageindex=1,int pagesize = 10)
        {
            try
            {
                return View(portalService.GetInnovateList(pageindex,pagesize));
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return Content(CommonConst.SystemErrorMessage);
            }
        }
        /// <summary>
        /// 得到一个专家
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Route("~/getexpert")]
        public IActionResult GetExpert(string id)
        {
            try
            {
                return Json(new { success = true, msg = CommonConst.Success, data = portalService.GetExpert(id) });
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return Json(new { success = false,msg = CommonConst.SystemErrorMessage});
            }
        }
        #endregion

        #region 支持
        /// <summary>
        /// 支持
        /// </summary>
        /// <returns></returns>
        [Route("~/support")]
        [Route("~/support.html")]
        public IActionResult Support()
        {
            try
            {
                return View(portalService.GetSupportInfo());
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return Content(CommonConst.SystemErrorMessage);
            }
        }
        #endregion

        #region 公司，关于我们
        /// <summary>
        /// 公司，关于我们
        /// </summary>
        /// <returns></returns>
        [Route("~/about")]
        [Route("~/about.html")]
        public IActionResult About()
        {
            try
            {
                return View(portalService.GetAboutInfo());
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return Content(CommonConst.SystemErrorMessage);
            }
        }
        #endregion

        #region 新闻
        /// <summary>
        /// 新闻
        /// </summary>
        /// <returns></returns>
        [Route("~/news")]
        [Route("~/news.html")]
        public IActionResult News()
        {
            try
            {
                return View(portalService.GetNewsInfo());
            }
            catch(Exception ex)
            {
                LogHelper.Error(ex);
                return Content(CommonConst.SystemErrorMessage);
            }
        }
        /// <summary>
        /// 新闻详情
        /// </summary>
        /// <returns></returns>
        [Route("~/detail")]
        [Route("~/detail.html")]
        public IActionResult Detail(string id)
        {
            try
            {
                return View(portalService.GetNewsDetailInfo(id));
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return Content(CommonConst.SystemErrorMessage);
            }
        }
        #endregion

        #region 联系我们
        /// <summary>
        /// 联系我们
        /// </summary>
        /// <returns></returns>
        [Route("~/contact")]
        [Route("~/contact.html")]
        public IActionResult Contact()
        {
            try
            {
                return View(portalService.GetContactInfo());
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return Content(CommonConst.SystemErrorMessage);
            }
        }
        #endregion

        #region 招聘
        /// <summary>
        /// 招聘
        /// </summary>
        /// <returns></returns>
        [Route("~/jobs")]
        [Route("~/jobs.html")]
        public IActionResult Jobs()
        {
            return View();
        }
        #endregion

        #region 订阅
        /// <summary>
        /// 得到一个专家
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Route("~/subscribe")]
        public IActionResult Subscribe(string email)
        {
            try
            {
                return Json(portalService.Subscribe(email));
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return Json(new { success = false, msg = CommonConst.SystemErrorMessage });
            }
        }
        /// <summary>
        /// 发邮件
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        [Route("~/send")]
        public IActionResult Send(EmailModel model)
        {
            try
            {
                return Json(portalService.SendMail(model));
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return Json(new { success = false, msg = CommonConst.SystemErrorMessage });
            }
        }
        #endregion

    }
}